﻿using Microsoft.AspNetCore.Authorization;

namespace ResourceBasedAuthApp.CustomRoleAuthorization
{
    public class CustomRoleAuthorizationHandler : AuthorizationHandler<CustomRoleRequirement>
    {
        public Task HandleAsync(AuthorizationHandlerContext context)
        {
            if (context.User.IsInRole("CustomRole"))
            {
                context.Succeed(new CustomRoleRequirement() {  FuncId="123"});
            }
            else
            {
                context.Fail();
            }

            return Task.CompletedTask;
        }

        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomRoleRequirement requirement)
        {
            return Task.CompletedTask;
        }
    }
    public class CustomRoleRequirement: IAuthorizationRequirement
    {
        public string FuncId { get; set; }
    }

}
